package com.example.find_friend_backend.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @Profile("dev") : 表示该配置类只有在 dev 开发环境才会生效
 */
@Configuration
@EnableSwagger2WebMvc
@Slf4j
@Profile("dev")
public class SwaggerConfig {
    @Bean(value = "defaultApi2")
    public Docket createRestApi() {
        log.info("准备生成接口文档...");
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("啵啵用户中心")
                .version("1.0")
                .termsOfServiceUrl("https://gitee.com/zhangdemimikoujian/projects")
                .description("啵啵用户中心接口文档")
                .contact(new Contact("bobo","https://gitee.com/zhangdemimikoujian/projects","xx@qq.com"))
                .build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("接口")
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.find_friend_backend.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}